package com.acwing.partition20;

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2022/1/20 19:28
 */
public class AC1913公平摄影 {

    private static final int N = (int) (1e5 + 10);
    private static int[][] nums = new int[N][2];
    private static Map<Integer, Integer> map = new HashMap<>();

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        for (int i = 1; i <= n; i++) {
            String[] s = reader.readLine().split("\\s+");
            nums[i] = new int[]{Integer.parseInt(s[0]), s[1].charAt(0) == 'G' ? 1 : -1};
        }
        Arrays.sort(nums, 1, n + 1, (o1, o2) -> Integer.compare(o1[0], o2[0]));
        //G H G G  H G
        //1 3 4 7 10 16
        //0 1 0 1  2  1  2
        //last用于记录连续相同段的起始位置
        int last = 0, answer = 0, sum = 0;
        for (int i = 1; i <= n; i++) {
            if (!map.containsKey(sum)) map.put(sum, nums[i][0]);
            sum += nums[i][1];
            if (map.containsKey(sum)) answer = Math.max(answer, nums[i][0] - map.get(sum));
            if (i == 1 || (nums[i][1] != nums[i - 1][1])) last = nums[i][0];
            answer = Math.max(answer, nums[i][0] - last);
        }
        writer.write(answer + "\n");
        writer.flush();
    }
}
